#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Service;
using System.Collections;
using Agresso.Interface.Layer.Domain;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class CommissionManagerListForm : Form
    {
        ProfitCentreService m_profitCentreService;
        ProfitCentre m_subject;
        SoftmarProfitCentreMappingForm m_parentForm;
        public CommissionManagerListForm(ProfitCentre a, SoftmarProfitCentreMappingForm parentForm)
        {
            InitializeComponent();
            m_subject = a;
            m_parentForm = parentForm;
            m_profitCentreService = new ProfitCentreService();
          
            //selectSubject();
        }

        //private void selectSubject()
        //{
        //    foreach (ListViewItem itm in listViewList.Items)
        //    {
        //        ProfitCentre a = (ProfitCentre)itm.Tag;
        //        if (a.profit_centre_id == m_subject.profit_centre_id)
        //        {
        //            itm.Selected = true;
        //            break;
        //        }
        //    }
        //}

        private void loadItems()
        {
            IList pcMasters = m_profitCentreService.GetAllProfitCentreMapping();
            foreach (ProfitCentre a in pcMasters)
            {
                if (a.agr_dim_value == string.Empty) continue;
                ListViewItem item = listViewList.Items.Add(a.agr_description);
                item.SubItems.Add(a.agr_dim_value);
                item.SubItems.Add(a.client);
                item.Tag = a;
                //item.Selected = a.profit_centre_id == m_subject.profit_centre_id;
            }
        }

        private void listViewList_DoubleClick(object sender, EventArgs e)
        {
            if(listViewList.SelectedItem==null)return;
            ProfitCentre a = (ProfitCentre)listViewList.SelectedItem.Tag;
            m_parentForm.UpdateCommissionManager(a);
            this.Close();
        }

        private void CommissionManagerListForm_Load(object sender, EventArgs e)
        {
            loadItems();
        }
    }
}